package org.linlinjava.litemall.admin.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;

@Slf4j
public class UrlFilter implements Filter {

    private static ArrayList<String> requestUrls = new ArrayList<>();
    static{
        requestUrls.add("/");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 过滤器初始化代码
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        // 检查请求的URL是否为你想要过滤的路径
        if (requestUrls.contains(httpServletRequest.getRequestURI())) {

        } else {
            log.info("请求的URL：" + httpServletRequest.getRequestURI());
            // 如果不是，则继续链路调用
            chain.doFilter(request, response);
        }
    }

    @Override
    public void destroy() {
        // 过滤器销毁代码
    }
}
